package com.hao.demo.hazelcast.controller;

import com.hao.demo.hazelcast.util.map.MapService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/demo")
public class DemoController {

    @Autowired
    private MapService mapService;
    
    @GetMapping("/add")
    public String add(@RequestParam("key") String key,
                      @RequestParam("value") String value){
        mapService.put(key, value);

        return "success";
    }

    @GetMapping("/get")
    public String get(@RequestParam("key") String key){
        Object value = mapService.get(key);

        return value == null ? "" : value.toString();
    }
}
